function RequestUtils() {
};

RequestUtils.prototype._read = function(name, func, condition, page, size, order, queue, callBackFunc, options) {
  var php = (options && options.php) ? options.php : '{{$smarty.const.READ|escape:'javascript'}}';
  if (options && options.pos) {
    var popupBox = new PopupBox();
    tmp = function(result, params) { popupBox._close();
                                     callBackFunc(result, params);
                                   };
    MiscUtils.load(popupBox, options.pos, 'Reading...');
  } else {
    tmp = callBackFunc;
  }
  var request = new Request(this._parseRead, { method: 'POST', context: this, params: { callBackFunc: tmp, options: options } });
  request._request(php + '?name=' + encodeURIComponent(name), ((func) ? '&f=' + encodeURIComponent(func) : '') + ((condition) ? '&c=' + encodeURIComponent(condition) : '') + ((page) ? '&p=' + encodeURIComponent(page) : '') + ((size) ? '&s=' + encodeURIComponent(size) : '') + ((order) ? '&o=' + encodeURIComponent(order) : '') + ((queue) ? '&q=' + encodeURIComponent(queue) : ''));
};

RequestUtils.prototype._parseRead = function(result, params) {
  if (params.callBackFunc) {
    params.callBackFunc(result, params);
  }
};

RequestUtils.prototype._write = function(name, objectsToAddOrUpdate, objectsToRemove, callBackFunc, options) {
  var func, php = (options && options.php) ? options.php : '{{$smarty.const.WRITE|escape:'javascript'}}';
  if (options && options.pos) {
    var popupBox = new PopupBox();
    tmp = function(result, params) { popupBox._close();
                                     callBackFunc(result, params);
                                   };
    MiscUtils.load(popupBox, options.pos, 'Writing...');
  } else {
    tmp = callBackFunc;
  }
  var request = new Request(this._parseWrite, { method: 'POST', context: this, params: { callBackFunc: tmp, options: options } });
  request._request(php + '?name=' + encodeURIComponent(name), 'obj=' + encodeURIComponent(JSON.stringify(objectsToAddOrUpdate)) + '&r=' + encodeURIComponent(JSON.stringify(objectsToRemove)));
};

RequestUtils.prototype._parseWrite = function(result, params) {
  if (params.callBackFunc) {
    params.callBackFunc(result, params);
  }
};


RequestUtils.prototype._write2 = function(q, callBackFunc, options) {
  var php = (options && options.php) ? options.php : '{{$smarty.const.WRITE2|escape:'javascript'}}';
  if (options && options.pos) {
    var popupBox = new PopupBox();
    tmp = function(result, params) { popupBox._close();
                                     callBackFunc(result, params);
                                   };
    MiscUtils.load(popupBox, options.pos, 'Writing...');
  } else {
    tmp = callBackFunc;
  }
  var request = new Request(this._parseWrite2, { method: 'POST', context: this, params: { callbackFunc: tmp, options: options } });
  request._request(php, 'q=' + encodeURIComponent(JSON.stringify(q)));
};

RequestUtils.prototype._parseWrite2 = function(result, params) {
  if (params.callbackFunc) {
    params.callbackFunc(result, params);
  }
};

RequestUtils.prototype._custom = function(action, args, callBackFunc, options) {
  var func, php = (options && options.php) ? options.php : '{{$smarty.const.CUSTOM|escape:'javascript'}}';
  if (options && options.pos) {
    var popupBox = new PopupBox();
    tmp = function(result, params) { popupBox._close();
                                     callBackFunc(result, params);
                                   };
    MiscUtils.load(popupBox, options.pos, 'Waiting...');
  } else {
    tmp = callBackFunc;
  }
  var request = new Request(this._parseCustom, { method: 'POST', context: this, params: { callBackFunc: tmp, options: options } });
  request._request(php + '?action=' + action, ((args) ? args : ''));
};

RequestUtils.prototype._parseCustom = function(result, params) {
  if (params.callBackFunc) {
    params.callBackFunc(result, params);
  }
};

RequestUtils.prototype._mysql = function(action, args, callBackFunc, options) {
  var func, php = (options && options.php) ? options.php : '{{$smarty.const.MYSQL|escape:'javascript'}}';
  if (options && options.pos) {
    var popupBox = new PopupBox();
    tmp = function(result, params) { popupBox._close();
                                     callBackFunc(result, params);
                                   };
    MiscUtils.load(popupBox, options.pos, 'Waiting...');
  } else {
    tmp = callBackFunc;
  }
  var request = new Request(this._parseCustom, { method: 'POST', context: this, params: { callBackFunc: tmp, options: options } });
  request._request(php + '?action=' + action, ((args) ? args : ''));
};

RequestUtils.prototype._parseMySql = function(result, params) {
  if (params.callBackFunc) {
    params.callBackFunc(result, params);
  }
};
